﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Configuration;
using Windows.Data.Xml.Dom;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;


namespace BoolanElement
{
    public delegate void DeleteElementHandler(BooUIBase uiElement, BooElement element);
    /// <summary>
    /// 元件基类
    /// </summary>
    public abstract class BooElement
    {

        public int UniqueID;
        
        /// <summary>
        /// 储存元件位置信息
        /// </summary>
        public BooElementTransform ElementTransform
        {
            get;
            set;
        }

        public BooSlide Parent;

        public BooElement()
        {
            ElementTransform = new BooElementTransform();

        }

        public BooElement(BooDocument doc)
        {
            ElementTransform = new BooElementTransform();
        }

        public void Delete(BooUIBase uiElement)
        {
            Parent.RemoveElement(uiElement);
            LostFocusObserver.Invoke();
        }

        public void Cut(BooUIBase uiElement)
        {
            GlobalVariable.ElementForPaste = uiElement.Element.Clone();
            Parent.RemoveElement(uiElement);

            LostFocusObserver.Invoke();
        }

        public void UpdateUniqueID(int id)
        {
            this.UniqueID = id;
        }

        public abstract BooElement Clone();
        /// <summary>
        /// 元件呈现
        /// </summary>
        public virtual async Task<BooUIBase> Render(SaveOriginalElement saveOriginal, SaveForRedoUndo saveForRedoUndo) { return null; }

        public virtual async Task<BooUIBase> RenderForThumbNails() { return null; }

        public abstract XElement SaveToXElement();

        public abstract void LoadFromXElement(XElement element);
    }
}
